/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package csse3004.GD.SysAdmin;

import csse3004.GD.DA.PollCreatorDA;
import csse3004.GD.DA.SysAdminDA;
import csse3004.GD.PC.PollCreatorService;
import csse3004.GD.PollAdminAccount;
import csse3004.GD.createGraph;
import java.util.ArrayList;
import java.util.Iterator;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 *
 * @author Tony Yu s4201567
 */
public class homeController implements Controller {

    protected final Log logger = LogFactory.getLog(getClass());
    private SysAdminService sds = new SysAdminDA();
    private PollCreatorService poll = new PollCreatorDA();

    public ModelAndView handleRequest(HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception {
        ArrayList<PollAdminAccount> adminList = new ArrayList<PollAdminAccount>();
        SystemReport sysReport = sds.getReportData();
        adminList = sds.getPollAdminList();

        createGraph userGraph = new createGraph(0,"Number of Users", "horizontal");
        userGraph.addValue("Poll Users", sysReport.getUserWeb());
        userGraph.addValue("Poll Masters", sysReport.getUserMaster());
        userGraph.addValue("Poll Creators", sysReport.getUserCreator());
        userGraph.addValue("Poll Administrators", sysReport.getUserAdmin());
        userGraph.addValue("System Administrators", sysReport.getUserSysAdmin());

        createGraph pollGraph = new createGraph(1,"Number of Polls  Total:"+sysReport.getPollTotal(), "pie");
  
        pollGraph.addValue("Pending Polls", sysReport.getPollPending());
        pollGraph.addValue("Open Polls", sysReport.getPollOpen());
        pollGraph.addValue("Complete Polls", sysReport.getPollComplete());
        
        ModelAndView mnv = new ModelAndView("home", "admin", adminList);
        mnv.addObject("pollGraph", pollGraph.display(500, 400));
        mnv.addObject("userGraph", userGraph.display(400, 400));
        mnv.addObject("sysReport", sysReport);
        return mnv;
    }
}